# Create your views here.
from django.shortcuts import render, get_object_or_404
from publications.models import Author, Publication

def mainIndex(request):
    return render(request,'publications/index.html')

def authorDetails(request, author_id):
    author = get_object_or_404(Author, pk=author_id)
    wok = author.publication_set.filter(source='ISI WOK')
    scopus = author.publication_set.filter(source='Scopus')
    gscholar = author.publication_set.filter(source='Google Scholar')
    
    return render(request, 'publications/author_details.html', 
                  {'author': author, 'pubWOK': wok, 'pubScopus':scopus, 'pubGScholar':gscholar,})

def authorIndex(request,department='ALL'):
    if department != 'ALL':
        all_authors = Author.objects.filter(department__exact=department)
    else:
        department = "TODOS LOS DEPARTAMENTOS (DIA, DATSI, DLSIIS)"
        all_authors = Author.objects.all()
    context = {'all_authors': all_authors,'department': department}
    return render(request, 'publications/author_index.html', context)

def publicationDetails(request, publication_id):
    publication = get_object_or_404(Publication, pk=publication_id)
    return render(request, 'publications/publication_details.html', {'publication': publication})

def scopusPublications(request,scopus_id):
    return render(request,'publications/scopus.html',{'authorId': scopus_id})

